package com.jingdianjichi.club.gateway.enums;

import lombok.Getter;

/**
 * 返回结果枚举
 */
@Getter
public enum ResultCodeEnum {
    /**
     * 成功
     */
    SUCCESS(200, "成功"),
    FAIL(500, "失败"),
    UNKNOWN_REASON(20001, "未知错误"),
    BAD_SQL_GRAMMAR(20002, "sql语法错误"),
    JSON_PARSE_ERROR(20003, "json解析异常"),
    PARAM_ERROR(20004, "参数不正确"),
    FILE_UPLOAD_ERROR(20005, "文件上传错误"),
    EXCEL_DATA_IMPORT_ERROR(20006, "Excel数据导入错误");

    private final Integer code;
    private final String desc;

    ResultCodeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据code获取枚举
     *
     * @param code code
     * @return 枚举
     */
    public static ResultCodeEnum getByCode(Integer code) {
        for (ResultCodeEnum value : ResultCodeEnum.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

}
